package com.show.business.device.controller;
import com.show.business.common.core.controller.BaseController;
import com.show.business.common.core.domain.AjaxResult;
import com.show.business.device.bean.DeviceManage;
import com.show.business.device.bean.UartTmp;
import com.show.business.device.bean.vo.DeviceGroupSet;
import com.show.business.device.mapper.UartTmpMapper;
import com.show.business.device.service.IDeviceManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 设备管理 前端控制器
 * </p>
 *
 * @author dvlp
 * @since 2023-10-14
 */
@Api(value = "设备-设备管理",description = "设备-设备管理")
@RestController
@RequestMapping("/device/deviceManage")
public class DeviceManageController extends BaseController {
    @Resource
    private IDeviceManageService deviceManageService;
    /**
     * 获取标签列表
     */
    @ApiOperation("获取标签列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", dataType = "Integer", dataTypeClass = Integer.class)
    })
    @GetMapping("/page")
    public Object getPage(DeviceManage deviceManage) {
        startPage();
        List<DeviceManage> list = deviceManageService.getList(deviceManage);
        return getDataTable(list);
    }
    /**
     * 添加标签
     */
    @ApiOperation("添加标签")
    @PostMapping("/save")
    public Object add(@RequestBody DeviceManage deviceManage) {
        return deviceManageService.saveInfo(deviceManage);
    }
    /**
     * 更新标签
     */
    @ApiOperation("更新标签")
    @PostMapping("/edit")
    public Object edit(@RequestBody DeviceManage deviceManage) {
        return deviceManageService.editInfo(deviceManage);
    }
    /**
     * 删除标签
     */
    @ApiOperation("删除")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "String", dataTypeClass = String.class)
    @DeleteMapping("/del")
    public Object del(@RequestParam String[] id) {
        return deviceManageService.delInfos(id);
    }
    /**
     * 标签详情
     */
    @ApiOperation("详情")
    @ApiImplicitParam(name = "id", value = "主键ID", required = true, dataType = "String", dataTypeClass = String.class)
    @GetMapping("/info")
    public Object getGoodsLabel(@RequestParam String id) {
        return deviceManageService.getInfo(id);
    }

    /**
     * 启用设备
     */
    @ApiOperation("启用设备")
    @GetMapping("/enable")
    public Object enable(@RequestParam String id) {
        return deviceManageService.enable(id);
    }

    /**
     * 禁用设备
     */
    @ApiOperation("禁用设备")
    @GetMapping("/disable")
    public Object disable(@RequestParam String id) {
        return deviceManageService.disable(id);
    }

    /**
     * 分组设备列表
     */
    @GetMapping("/getGroupDeviceList")
    public Object getGroupDeviceList(DeviceManage deviceManage) {
        startPage();
        List<DeviceManage> list = deviceManageService.getListByGroup(deviceManage);
        return getDataTable(list);
    }

    /**
     * 未分组设备列表
     */
    @GetMapping("/getNoGroupDeviceList")
    public Object getNoGroupDeviceList(DeviceManage deviceManage) {
        startPage();
        List<DeviceManage> list = deviceManageService.getListByNoGroup(deviceManage);
        return getDataTable(list);
    }

    /**
     * 取消设备分组
     */
    @PutMapping("/groupDeviceCancel")
    public AjaxResult groupDeviceCancel(@RequestBody DeviceGroupSet groupSet)
    {
        return deviceManageService.groupDeviceCancel(groupSet);
    }

    /**
     * 批量取消设备分组
     */
    @PutMapping("/groupDeviceCancelAll")
    public AjaxResult groupDeviceCancelAll(String groupId, String[] deviceIds)
    {
        return deviceManageService.groupDeviceCancelAll(groupId, deviceIds);
    }

    /**
     * 批量选择分组设备
     */
    @PutMapping("/groupDeviceSelectAll")
    public AjaxResult groupDeviceSelectAll(String groupId, String[] deviceIds)
    {
        return deviceManageService.groupDeviceSelectAll(groupId, deviceIds);
    }

    /**
     * 获取标签列表
     */
    @ApiOperation("获取标签列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页大小", dataType = "Integer", dataTypeClass = Integer.class)
    })
    @GetMapping("/deviceLineList")
    public Object deviceLineList(DeviceManage deviceManage) {
        startPage();
        List<DeviceManage> list = deviceManageService.getDeviceList(deviceManage);
        return getDataTable(list);
    }
}
